package com.polaris.live.common.mvvm.base2

import android.os.Bundle
import androidx.viewbinding.ViewBinding
import com.polaris.live.common.mvvm.activity.BaseVmVbActivity
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.util.loading.LoadingUtils
import com.polaris.live.common.util.loading.OnCancelListener
import com.polaris.live.common.util.loading.OnDismissListener

/**
 * 继承这个BaseVbActivity就不需要强制重写showLoading和dismissLoading了    至于为什么  主要是我看着难受
 *
 * @author Created by 半仙 on 2023/7/31/031 15:22
 */
abstract class BaseVbActivity<VM : BaseViewModel, VB : ViewBinding> : BaseVmVbActivity<VM, VB>() {

    abstract override fun initView(savedInstanceState: Bundle?)

    /**
     * 创建liveData观察者
     */
    override fun createObserver() {}

    /**
     * 打开等待框
     */
    override fun showLoading(
        message: String,
        cancelable: Boolean,
        hasShadowBg: Boolean,
        cancelTime: Long,
        waitTime: Long,
        useView: Boolean,
        onCancelListener: OnCancelListener?,
        onDismissListener: OnDismissListener?
    ) {
        if (!isFinishing) {
            LoadingUtils.showLoadingDialog(
                this,
                message,
                cancelable,
                hasShadowBg,
                cancelTime,
                waitTime,
                useView,
                onCancelListener,
                onDismissListener
            )
        }
    }

    /**
     * 关闭等待框
     */
    override fun dismissLoading(waitTime: Long) {
        LoadingUtils.dismissLoadingDialog(waitTime)
    }
}